Skip to content

Commit 2fc0e58

Browse files
committed
Add proxy program to DynamicAccount interface.
1 parent 015fdc0 commit 2fc0e58

7 files changed

Lines changed: 18 additions & 6 deletions

File tree

downloadMappings.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55
rm -rf glam/
66
git clone -n --depth=1 --filter=tree:0 https://github.com/glamsystems/glam-sdk.git glam
77
cd glam
8-
git sparse-checkout set --no-cone /remapping
8+
git sparse-checkout set --no-cone /remapping /remapping_v1
99
git checkout
1010

1111
cd ..

ix-proxy/src/main/java/systems/glam/ix/proxy/DynamicAccount.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package systems.glam.ix.proxy;
22

3+
import software.sava.core.accounts.PublicKey;
34
import software.sava.core.accounts.meta.AccountMeta;
45

56
@FunctionalInterface
67
public interface DynamicAccount<A> {
78

89
void setAccount(final AccountMeta[] mappedAccounts,
10+
final PublicKey proxyProgram,
911
final AccountMeta cpiProgram,
1012
final AccountMeta feePayer,
1113
final A runtimeAccounts);

ix-proxy/src/main/java/systems/glam/ix/proxy/IndexedCpiProgram.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package systems.glam.ix.proxy;
22

3+
import software.sava.core.accounts.PublicKey;
34
import software.sava.core.accounts.meta.AccountMeta;
45

56
public record IndexedCpiProgram<A>(int index) implements DynamicAccount<A> {
67

78
@Override
89
public void setAccount(final AccountMeta[] mappedAccounts,
10+
final PublicKey proxyProgram,
911
final AccountMeta cpiProgram,
1012
final AccountMeta feePayer,
1113
final A runtimeAccounts) {

ix-proxy/src/main/java/systems/glam/ix/proxy/IndexedFeePayer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package systems.glam.ix.proxy;
22

3+
import software.sava.core.accounts.PublicKey;
34
import software.sava.core.accounts.meta.AccountMeta;
45

56
public record IndexedFeePayer<A>(int index) implements DynamicAccount<A> {
67

78
@Override
89
public void setAccount(final AccountMeta[] mappedAccounts,
10+
final PublicKey proxyProgram,
911
final AccountMeta cpiProgram,
1012
final AccountMeta feePayer,
1113
final A runtimeAccounts) {

ix-proxy/src/main/java/systems/glam/ix/proxy/IxMapConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public <A> IxProxy<A> createProxy(final AccountMeta invokedProxyProgram,
6969
if (checkIndexes[index]) {
7070
throw new IllegalStateException(String.format(
7171
"Duplicate index %d in dynamic accounts. CPI IX: %s, Proxy IX: %s",
72-
account.index(), cpiIxName, proxyIxName
72+
index, cpiIxName, proxyIxName
7373
));
7474
} else {
7575
checkIndexes[index] = true;
@@ -80,7 +80,7 @@ public <A> IxProxy<A> createProxy(final AccountMeta invokedProxyProgram,
8080
if (checkIndexes[index]) {
8181
throw new IllegalStateException(String.format(
8282
"Duplicate index %d in static accounts. CPI IX: %s, Proxy IX: %s",
83-
account.index(), cpiIxName, proxyIxName
83+
index, cpiIxName, proxyIxName
8484
));
8585
} else {
8686
checkIndexes[index] = true;

ix-proxy/src/main/java/systems/glam/ix/proxy/IxProxyRecord.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ public Instruction mapInstructionUnchecked(final AccountMeta readCpiProgram,
4545

4646
final var mappedAccounts = new AccountMeta[this.numAccounts + numExtraAccounts];
4747
for (final var dynamicAccount : dynamicAccounts) {
48-
dynamicAccount.setAccount(mappedAccounts, readCpiProgram, feePayer, runtimeAccounts);
48+
dynamicAccount.setAccount(
49+
mappedAccounts,
50+
invokedProxyProgram.publicKey(),
51+
readCpiProgram,
52+
feePayer,
53+
runtimeAccounts
54+
);
4955
}
5056
for (final var staticAccount : staticAccounts) {
5157
staticAccount.setAccount(mappedAccounts);

ix-proxy/src/test/java/systems/glam/ix/proxy/GlamIxTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public static <A> TransactionMapper<A> createMapper(final Path mappingFileDirect
8181
final int index = accountConfig.index();
8282
final boolean w = accountConfig.writable();
8383
return switch (accountConfig.name()) {
84-
case "glam_state" -> (mappedAccounts, _, _, vaultAccounts) -> mappedAccounts[index] = w
84+
case "glam_state" -> (mappedAccounts, _, _, _, vaultAccounts) -> mappedAccounts[index] = w
8585
? vaultAccounts.writeGlamState() : vaultAccounts.readGlamState();
86-
case "glam_vault" -> (mappedAccounts, _, _, vaultAccounts) -> mappedAccounts[index] = w
86+
case "glam_vault" -> (mappedAccounts, _, _, _, vaultAccounts) -> mappedAccounts[index] = w
8787
? vaultAccounts.writeGlamVault() : vaultAccounts.readGlamVault();
8888
case "glam_signer" -> accountConfig.createFeePayerAccount();
8989
case "cpi_program" -> accountConfig.createReadCpiProgram();

0 commit comments

Comments
 (0)