Skip to content

Commit

Permalink
Merge branch 'main' into return-zero-in-max-functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuba authored May 3, 2024
2 parents 2f3270b + 866052c commit 48a2ddb
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 86 deletions.
38 changes: 18 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions solidity/contracts/stBTC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,21 @@ contract stBTC is ERC4626Fees, PausableOwnable {
return convertToAssets(balanceOf(account));
}

/// @dev Transfers a `value` amount of tokens from `from` to `to`, or
/// alternatively mints (or burns) if `from` (or `to`) is the zero
/// address. All customizations to transfers, mints, and burns should
/// be done by overriding this function.
/// @param from Sender of tokens.
/// @param to Receiver of tokens.
/// @param value Amount of tokens to transfer.
function _update(
address from,
address to,
uint256 value
) internal override whenNotPaused {
super._update(from, to, value);
}

/// @return Returns entry fee basis point used in deposits.
function _entryFeeBasisPoints() internal view override returns (uint256) {
return entryFeeBasisPoints;
Expand Down
19 changes: 19 additions & 0 deletions solidity/test/stBTC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,25 @@ describe("stBTC", () => {
it("should return 0 when calling maxWithdraw", async () => {
expect(await stbtc.maxWithdraw(depositor1)).to.be.eq(0)
})

it("should pause transfers", async () => {
await expect(
stbtc.connect(depositor1).transfer(depositor2, amount),
).to.be.revertedWithCustomError(stbtc, "EnforcedPause")
})

it("should pause transfersFrom", async () => {
await expect(
stbtc
.connect(depositor1)
.approve(depositor2.address, amount)
.then(() =>
stbtc
.connect(depositor2)
.transferFrom(depositor1, depositor2, amount),
),
).to.be.revertedWithCustomError(stbtc, "EnforcedPause")
})
})
})

Expand Down
74 changes: 51 additions & 23 deletions subgraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ create a private one

1. Install Docker on your local machine:

- Mac: https://docs.docker.com/desktop/install/mac-install/
- Windows: https://docs.docker.com/desktop/install/windows-install/
- Linux: https://docs.docker.com/desktop/install/linux-install/
- [Mac](https://docs.docker.com/desktop/install/mac-install/)
- [Windows](https://docs.docker.com/desktop/install/windows-install/)
- [Linux](https://docs.docker.com/desktop/install/linux-install/)

2. Set the API key in the `docker-compose.yaml` file.

Expand Down Expand Up @@ -78,39 +78,67 @@ Note: use it only if your subgraph is not created in the local Graph node.

### Deploy the subgraph to Subgraph Studio

1. You need to connect wallet to use Subgraph Studio [Metamask, WalletConnect, Coinbase Wallet or Safe].
1. Go to [Subgraph Studio](https://thegraph.com/studio/). Connect wallet to use
the Subgraph Studio using Metamask, WalletConnect, Coinbase Wallet or Safe.
Use a dedicated account for the Acre team.

2. Once the account is connected, all subgraphs are available in the [My
Dashboard](https://thegraph.com/studio/) tab. Select the correct subgraph.

3. Before being able to deploy subgraph to the Subgraph Studio, you need to
login into your account within the CLI.

```
https://thegraph.com/studio/
graph auth --studio <DEPLOY KEY>
```

2. We're going to create a Subgraph. To do that you need to click Create a Subgraph button in My Dashboard of Subgraph Studio.

3. In the next step you'll need to add name of Subgraph and choose indexed blockchain from the list.
The `<DEPLOY_KEY>` can be found on "My Subgraphs" page or subgraph details
page.

4. Once your subgraph has been created in Subgraph Studio you can initialize the subgraph code using this command:
4. Deploying a Subgraph to Subgraph Studio

```
graph init --studio <SUBGRAPH_SLUG>
graph deploy --studio <SUBGRAPH_SLUG>
```

The <SUBGRAPH_SLUG> value can be found on your subgraph details page in Subgraph Studio
(https://thegraph.com/docs/en/deploying/deploying-a-subgraph-to-studio/#create-your-subgraph-in-subgraph-studio)
The `<SUBGRAPH_SLUG>` can be found on subgraph details page in the Subgraph
Studio.

5. Before being able to deploy your subgraph to Subgraph Studio, you need to login into your account within the CLI.
After running this command, the CLI will ask for a version label, you can
name it however you want, you can use labels such as 0.1 and 0.2 or use
letters as well such as uniswap-v2-0.1.

```
graph auth --studio <DEPLOY KEY>
```
If you have any problems, take a look
[here](https://thegraph.com/docs/en/deploying/deploying-a-subgraph-to-studio/).

The <SUBGRAPH_SLUG> can be found on your "My Subgraphs" page or your subgraph details page.
### Publish the subgraph to the Decentralized Network

6. Deploying a Subgraph to Subgraph Studio
Subgraphs can be published to the decentralized network directly from the
Subgraph Studio dashboard.

```
graph deploy --studio <SUBGRAPH_SLUG>
```
1. Select the correct subgraph from the Subgraph Studio.

2. Click the "Publish" button

3. While you’re going through your publishing flow, you’ll be able to push to
either Arbitrum One or Arbitrum Sepolia.

- Publishing to Arbitrum Sepolia is free. This will allow you to see how the
subgraph will work in the [Graph Explorer](https://thegraph.com/explorer)
and will allow you to test curation elements. This is recommended for
testing purposes only.

4. During the publication flow, it is possible to add signal to your subgraph.
This is not a required step and you can add GRT signal to a published
subgraph from the Graph Explorer later.

- Adding signal to a subgraph which is not eligible for rewards will not
attract additional Indexers. More info
[here](https://thegraph.com/docs/en/publishing/publishing-a-subgraph/#adding-signal-to-your-subgraph).

After running this command, the CLI will ask for a version label, you can name it however you want, you can use labels such as 0.1 and 0.2 or use letters as well such as uniswap-v2-0.1.
5. Click the "Publish new Subgraph" button. Once a subgraph is published, it
will be available to view in the [Graph
Explorer](https://thegraph.com/explorer).

7. More information about deploying your subgraph to Subgraph Studio: https://thegraph.com/docs/en/deploying/subgraph-studio/
If you have any problems, take a look
[here](https://thegraph.com/docs/en/publishing/publishing-a-subgraph/).
6 changes: 3 additions & 3 deletions subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
"lint:config:fix": "prettier -w '**/*.@(json|yaml|toml)'"
},
"dependencies": {
"@graphprotocol/graph-cli": "0.68.3",
"@graphprotocol/graph-ts": "0.32.0",
"@graphprotocol/graph-cli": "0.71.0",
"@graphprotocol/graph-ts": "0.35.1",
"assemblyscript": "0.19.23"
},
"devDependencies": {
"@thesis-co/eslint-config": "github:thesis/eslint-config#7b9bc8c",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"eslint": "^8.54.0",
"matchstick-as": "0.5.0",
"matchstick-as": "0.6.0",
"prettier": "^3.1.0"
}
}
7 changes: 4 additions & 3 deletions subgraph/src/bitcoin-depositor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ import {
getOrCreateDeposit,
getOrCreateEvent,
} from "./utils"
import { findBitcoinTransactionIdFromTransactionReceipt } from "./tbtc-utils"

export function handleDepositInitialized(event: DepositInitializedEvent): void {
const depositOwnerEntity = getOrCreateDepositOwner(event.params.depositOwner)
const depositEntity = getOrCreateDeposit(
event.params.depositKey.toHexString(),
)

// TODO: Get the bitcoin transaction hash from this Ethereum transaction
// by finding the `DepositRevealed` event in logs from the tBTC-v2 Bridge
// contract.
depositEntity.depositOwner = depositOwnerEntity.id
depositEntity.initialDepositAmount = event.params.initialAmount

depositEntity.bitcoinTransactionId =
findBitcoinTransactionIdFromTransactionReceipt(event.receipt)

const eventEntity = getOrCreateEvent(
`${event.transaction.hash.toHexString()}_DepositInitialized`,
)
Expand Down
65 changes: 65 additions & 0 deletions subgraph/src/tbtc-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
Address,
ethereum,
crypto,
ByteArray,
BigInt,
Bytes,
dataSource,
} from "@graphprotocol/graph-ts"

const DEPOSIT_REVEALED_EVENT_SIGNATURE = crypto.keccak256(
ByteArray.fromUTF8(
"DepositRevealed(bytes32,uint32,address,uint64,bytes8,bytes20,bytes20,bytes4,address)",
),
)

// eslint-disable-next-line import/prefer-default-export
export function findBitcoinTransactionIdFromTransactionReceipt(
transactionReceipt: ethereum.TransactionReceipt | null,
): string {
const tbtcV2BridgeAddress = Address.fromBytes(
dataSource.context().getBytes("tbtcBridgeAddress"),
)

if (!transactionReceipt) {
throw new Error("Transaction receipt not available")
}

// We must cast manually to `ethereum.TransactionReceipt` otherwise
// AssemblyScript will fail.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const receipt = transactionReceipt as ethereum.TransactionReceipt

let depositRevealedLogIndex = -1
for (let i = 0; i < receipt.logs.length; i += 1) {
const receiptLog = receipt.logs[i]

if (
receiptLog.address.equals(tbtcV2BridgeAddress) &&
receiptLog.topics[0].equals(DEPOSIT_REVEALED_EVENT_SIGNATURE)
) {
depositRevealedLogIndex = i
}
}

if (depositRevealedLogIndex < 0) {
throw new Error("Cannot find `DepositRevealed` event in transaction logs")
}

const depositRevealedLog = receipt.logs[depositRevealedLogIndex]

// Bitcoin transaction hash in little-endian byte order. The first 32 bytes
// (w/o `0x` prefix) points to the Bitcoin transaction hash.
const bitcoinTxHash = depositRevealedLog.data.toHexString().slice(2, 66)

// Bitcoin transaction id in the same byte order as used by the
// Bitcoin block explorers.
const bitcoinTransactionId = BigInt.fromUnsignedBytes(
Bytes.fromHexString(bitcoinTxHash),
)
.toHexString()
.slice(2)

return bitcoinTransactionId
}
4 changes: 4 additions & 0 deletions subgraph/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ dataSources:
- kind: ethereum
name: BitcoinDepositor
network: sepolia
context:
tbtcBridgeAddress:
type: Bytes
data: "0x9b1a7fE5a16A15F2f9475C5B231750598b113403"
source:
address: "0x2F86FE8C5683372Db667E6f6d88dcB6d55a81286"
abi: BitcoinDepositor
Expand Down
Loading

0 comments on commit 48a2ddb

Please sign in to comment.