-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: repo scripts * fix: coder type * chore: replace hardcoded script with actual Sway code
- Loading branch information
Showing
19 changed files
with
130 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
forc build -p src/contract-call-script | ||
pnpm exec ts-node scripts/process-contract-call-script.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
#!/bin/sh | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
scripts/build-contract-call-script.sh | ||
forc build -p src/storage-test-contract | ||
forc build -p src/call-test-contract | ||
forc build -p src/token-test-contract/token_abi | ||
forc build -p src/token-test-contract/token_contract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { hexlify } from '@ethersproject/bytes'; | ||
import { NumberCoder } from '@fuel-ts/abi-coder'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
// Patches the script binary to add the binary size | ||
const getPatchedScript = (bytes: Uint8Array): string => { | ||
// Encode length and right-pad to the size of b256 | ||
const encodedSize = new NumberCoder('encodedSize', 'u64').encode(bytes.length); | ||
const paddedSize = new Uint8Array(32); | ||
paddedSize.set(encodedSize); | ||
// Patch the binary with the encoded size | ||
const magic = '0xd5579c46dfcc7f18207013e65b44e4cb4e2c2298f4ac457ba8f82743f31e930b'; | ||
const patched = hexlify(bytes).replace(magic.slice(2), hexlify(paddedSize).slice(2)); | ||
return patched; | ||
}; | ||
|
||
const srcPath = path.join(__dirname, '../src'); | ||
|
||
const bytes = fs.readFileSync( | ||
path.join(srcPath, './contract-call-script/out/debug/contract-call-script.bin') | ||
); | ||
|
||
const patchedBytes = getPatchedScript(bytes); | ||
|
||
const indexTs = `export default '${patchedBytes}';\n`; | ||
|
||
fs.writeFileSync(path.join(srcPath, './contract-call-script/index.ts'), indexTs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[[package]] | ||
name = 'call-test' | ||
dependencies = ['std git+https://github.com/fuellabs/sway?tag=v0.12.2#2b6e9384f06692ec627293ae5db5e2f748fe2c30'] | ||
|
||
[[package]] | ||
name = 'core' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'git+https://github.com/fuellabs/sway?tag=v0.12.2#2b6e9384f06692ec627293ae5db5e2f748fe2c30' | ||
dependencies = ['core'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+24 Bytes
(100%)
packages/contract/src/call-test-contract/out/debug/call-test.bin
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[[package]] | ||
name = 'contract-call-script' | ||
dependencies = ['std git+https://github.com/fuellabs/sway?tag=v0.12.2#2b6e9384f06692ec627293ae5db5e2f748fe2c30'] | ||
|
||
[[package]] | ||
name = 'core' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'git+https://github.com/fuellabs/sway?tag=v0.12.2#2b6e9384f06692ec627293ae5db5e2f748fe2c30' | ||
dependencies = ['core'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[project] | ||
name = "contract-call-script" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default '0x900000044700000000000000000000c85dfcc00110fff3001a4c5000910000301a40c000504530185f4d00035d43f006104103005d450000504130285f4d1005504130185d453003504130285d41300510450440504130205f4d1004504130205d4530045d43f004104504405d43f00510450440504130105f4d1002504130205d4530045d43f00410450440504130005f4d1000504130205d453004504130085f4d1001504130105d493002504130005d453000504130085d4130015d4510002d49140a2400000000000000000001000000000000000000000000000000000000000000000000000000000000000020000000000000000800000000000000c8'; |
Binary file added
BIN
+256 Bytes
packages/contract/src/contract-call-script/out/debug/contract-call-script.bin
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
script; | ||
|
||
use std::context::registers::*; | ||
|
||
const CONTRACT_ID_LEN = 32; | ||
const WORD_SIZE = 8; | ||
|
||
// User of this script will replace this magic b256 in the binary | ||
// with the length of the binary | ||
const SCRIPT_LENGTH_BYTES = 0xd5579c46dfcc7f18207013e65b44e4cb4e2c2298f4ac457ba8f82743f31e930b; | ||
fn get_script_length() -> u64 { | ||
asm(out, r1: SCRIPT_LENGTH_BYTES) { | ||
lw out r1 i0; | ||
out: u64 | ||
} | ||
} | ||
|
||
fn get_script_data_offset() -> u64 { | ||
let is = instrs_start(); | ||
let script_length = get_script_length(); | ||
is + script_length | ||
} | ||
|
||
fn main() { | ||
let script_data_offset = get_script_data_offset(); | ||
let call_data_offset = script_data_offset + CONTRACT_ID_LEN + WORD_SIZE; | ||
let amount_offset = script_data_offset + CONTRACT_ID_LEN; | ||
let asset_id_offset = script_data_offset; | ||
|
||
asm(r1: call_data_offset, r2: amount_offset, r3: asset_id_offset) { | ||
lw r2 r2 i0; | ||
call r1 r2 r3 cgas; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/contract/src/token-test-contract/token_abi/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[[package]] | ||
name = 'core' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'git+https://github.com/fuellabs/sway?tag=v0.12.2#2b6e9384f06692ec627293ae5db5e2f748fe2c30' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'token_abi' | ||
dependencies = ['std git+https://github.com/fuellabs/sway?tag=v0.12.2#2b6e9384f06692ec627293ae5db5e2f748fe2c30'] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters